import os

basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
    """基础配置参数"""
    PORT = 5000
    HOST = "0.0.0.0"
    # 设置秘钥，在使用 CSRF 时必须
    SECRET_KEY = "my flask app"
    # 配置时区
    SCHEDULER_TIMEZONE = 'Asia/Shanghai'
    # 调度器开关
    SCHEDULER_API_ENABLED = True
    # 设置白名单
    SCHEDULER_ALLOWED_HOSTS = ['*']


class DevelopmentConfig(Config):
    """开发模式的配置信息"""

    BEBUG = True
    # MYSQL数据库配置
    DB_HOST = os.getenv("DB_HOST")
    DB_PORT = os.getenv("DB_PORT")
    DB_USER = os.getenv("DB_USER")
    DB_PASSWORD = os.getenv("DB_PASSWORD")
    DATABASE = os.getenv("DATABASE")
    DB_URI = 'mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset-utf8'.format(username=DB_USER,
                                                                                            password=DB_PASSWORD,
                                                                                            host=DB_HOST, port=DB_PORT,
                                                                                            db=DATABASE)
    SQLALCHEMY_ECHO = False
    # 数据库连接的实例化
    SQLALCHEMY_DATABASE_URI = DB_URI
    # 关闭动态跟踪;是否跟踪对象的修改，默认为None，这里设置为False
    SQLALCHEMY_TRACK_MODIFICATIONS = False


class TestingConfig(Config):
    """测试环境配置信息"""
    TESTING = True
    DEBUG = True
    TESTING_DB_Name = 'data-test.sqlite'
    # 设置 SQLite 数据库连接的 URI
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, TESTING_DB_Name)


class ProductionConfig(Config):
    """生产环境配置信息"""
    DEBUG = False


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': TestingConfig
}
